{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python385jvsc74a57bd004089dccd669f5475382045dd9eff7870585234f8cdbd51ae6db76ccd1cd85e5",
   "display_name": "Python 3.8.5 64-bit ('base': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# AutoEncoder\n",
    "Work in progress..."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "from IPython.display import set_matplotlib_formats\n",
    "set_matplotlib_formats('png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tsod"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "metadata": {},
     "execution_count": 9
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAADuCAYAAAAk94yFAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAzY0lEQVR4nO2dd5wVRbbHf2ciGRRGJI9EJSOzCApiQEVRWd0VdU1rWHy6hue6Kqvurooob82uEbOr4poDA0oGQUGHqEiGIYchzhAmn/dH973T997ue/vezjPn+/nwYW6H6lPdVadOnTpVRcwM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wRBEIQaRJELgiAEHFHkgiAIAUcUuSAIQsARRS4IghBwRJELgiAEHFHkgiAIAef/AWvVlsEcg/8IAAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     }
    }
   ],
   "source": [
    "file_path = os.path.join(\"..\", \"tests\", \"data\", \"Ballen_20150218-20201222.csv\")\n",
    "df = pd.read_csv(file_path, index_col=0, parse_dates=True)\n",
    "data = df.water_level\n",
    "data.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "range_anomalies = tsod.RangeDetector(-1, 1.3).detect(data)\n",
    "data_clean = data.copy()\n",
    "data_clean[range_anomalies.values] = np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense (Dense)                (None, 100)               10100     \n",
      "_________________________________________________________________\n",
      "dropout (Dropout)            (None, 100)               0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 100)               10100     \n",
      "_________________________________________________________________\n",
      "dropout_1 (Dropout)          (None, 100)               0         \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 64)                6464      \n",
      "_________________________________________________________________\n",
      "dropout_2 (Dropout)          (None, 64)                0         \n",
      "_________________________________________________________________\n",
      "dense_3 (Dense)              (None, 32)                2080      \n",
      "_________________________________________________________________\n",
      "dropout_3 (Dropout)          (None, 32)                0         \n",
      "_________________________________________________________________\n",
      "dense_4 (Dense)              (None, 32)                1056      \n",
      "_________________________________________________________________\n",
      "dropout_4 (Dropout)          (None, 32)                0         \n",
      "_________________________________________________________________\n",
      "dense_5 (Dense)              (None, 64)                2112      \n",
      "_________________________________________________________________\n",
      "dropout_5 (Dropout)          (None, 64)                0         \n",
      "_________________________________________________________________\n",
      "dense_6 (Dense)              (None, 100)               6500      \n",
      "=================================================================\n",
      "Total params: 38,412\n",
      "Trainable params: 38,412\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "None\n",
      "Epoch 1/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 2.5079 - val_loss: 1.1116\n",
      "Epoch 2/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 1.0905 - val_loss: 1.0523\n",
      "Epoch 3/20\n",
      "1268/1268 [==============================] - 3s 3ms/step - loss: 1.0554 - val_loss: 1.0362\n",
      "Epoch 4/20\n",
      "1268/1268 [==============================] - 3s 3ms/step - loss: 1.0497 - val_loss: 1.0169\n",
      "Epoch 5/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 1.0144 - val_loss: 1.0104\n",
      "Epoch 6/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 0.9971 - val_loss: 1.0019\n",
      "Epoch 7/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 0.9983 - val_loss: 0.9990\n",
      "Epoch 8/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 0.9975 - val_loss: 0.9944\n",
      "Epoch 9/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 1.0046 - val_loss: 0.9978\n",
      "Epoch 10/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 1.0002 - val_loss: 0.9945\n",
      "Epoch 11/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 0.9948 - val_loss: 0.9953\n",
      "Epoch 12/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 0.9816 - val_loss: 0.9933\n",
      "Epoch 13/20\n",
      "1268/1268 [==============================] - 3s 2ms/step - loss: 0.9876 - val_loss: 0.9944\n",
      "Epoch 14/20\n",
      "1268/1268 [==============================] - 4s 3ms/step - loss: 0.9908 - val_loss: 0.9937\n",
      "Epoch 15/20\n",
      "1268/1268 [==============================] - 4s 3ms/step - loss: 0.9917 - val_loss: 0.9922\n",
      "Epoch 16/20\n",
      "1268/1268 [==============================] - 4s 4ms/step - loss: 1.0057 - val_loss: 1.0094\n",
      "Epoch 17/20\n",
      "1268/1268 [==============================] - 4s 3ms/step - loss: 1.0045 - val_loss: 1.0067\n",
      "Epoch 18/20\n",
      "1268/1268 [==============================] - 4s 3ms/step - loss: 0.9970 - val_loss: 1.0041\n",
      "Epoch 19/20\n",
      "1268/1268 [==============================] - 4s 3ms/step - loss: 1.0081 - val_loss: 0.9915\n",
      "Epoch 20/20\n",
      "1268/1268 [==============================] - 3s 3ms/step - loss: 0.9843 - val_loss: 0.9926\n"
     ]
    }
   ],
   "source": [
    "from tsod.autoencoders import AutoEncoder\n",
    "from tsod.features import lag_time_series\n",
    "\n",
    "normal_data = data_clean[\"2015\"].interpolate()  # fill gaps in chosen \"normal\" data period\n",
    "max_lag = 100  # window_size\n",
    "normal_data_lagged_features = lag_time_series(normal_data, lags=range(max_lag)).dropna() # TODO put in pipeline\n",
    "\n",
    "detector = AutoEncoder(epochs=20) # hidden_neurons=[max_lag, 3, 3, max_lag]\n",
    "\n",
    "detector.fit(normal_data_lagged_features)\n",
    "\n",
    "data_lagged_features = lag_time_series(data.interpolate(), lags=range(max_lag)).dropna()\n",
    "\n",
    "anomalies = detector.detect(data_lagged_features) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}